#!/usr/bin/env python3

# Copyright (c) 2020-2021 Fpemud <fpemud@sina.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.


from .._util import WinFile


class BillboardFile(WinFile):

    def __init__(self, ts):
        self._ts = ts
        self._panels = []

    def add_panel(self, count, title, text):
        assert len(self._panels) < 20                   # FIXME: I don't know, but there's a "PanelCount=20"
        self._panels.append((count, title, text))

    def get_filen_name(self):
        return "WIN95BB.INI"

    def get_content(self):
        buf = ""

        # setting part
        buf += self._heading.strip("\n") + "\n"
        buf += "\n"

        # panel part
        for i, data in enumerate(self._panels):
            count, title, text = data
            buf += "[Panel%d]\n" % (i)
            buf += "Count=%d\n" % (count)                       # how many seconds this panel lasts
            buf += "Title=%s\n" % (title)                       # note: title has "|" symbol, example: "Welcome |to the |Unattended |Boot CD |for Windows 98!"
            for j, line in enumerate(text.rstrip("\n").split("\n")):
                buf += "Text%d=\"%s\"\n" % (j, line)            # note: text also has "|" symbol

        return buf

    _heading = """
[Setting]
TitleFont=Arial
TitleFontSize_640=26
TitleFontWidth_640=12
TitleFontSize_800=40
TitleFontWidth_800=15
TitleFontSize_1024=48
TitleFontWidth_1024=20
TitleFontWeight=800
TextFont=Arial
TextFontSize_640=17
TextFontWidth_640=7
TextFontSize_800=21
TextFontWidth_800=8
TextFontSize_1024=24
TextFontWidth_1024=10
TextFontWeight=500
PanelCount=20
Animation=1
"""
